package edu.bbk.muc.lifetracker.common;

/**
 * Provides a plain object wrapper for acceleration values (instead of using
 * array of three floats).
 * @author irenatyler and romankirillov
 */
public class Acceleration {
  private static int hash(Object object, int nullHash) {
    return (object == null) ? nullHash : object.hashCode();
  }

  private Float xAcceleration;
  private Float yAcceleration;
  private Float zAcceleration;

  public Acceleration() {
  }

  public Acceleration(float xAcceleration, float yAcceleration, float zAcceleration) {
    this.xAcceleration = xAcceleration;
    this.yAcceleration = yAcceleration;
    this.zAcceleration = zAcceleration;
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof Acceleration) {
      return o.hashCode() == this.hashCode();
    } else {
      return false;
    }
  }

  public Float getXAcceleration() {
    return xAcceleration;
  }

  public Float getYAcceleration() {
    return yAcceleration;
  }

  public Float getZAcceleration() {
    return zAcceleration;
  }

  @Override
  public int hashCode() {
    // approach is shamelessly stolen but modified to serve our purpose
    // from Google Utils for Java (Google Guava).
    return (hash(xAcceleration, 0) + 0xDeadBeef)
        ^ (hash(yAcceleration, 0) + 0xBaadF00d)
        ^ hash(zAcceleration, 0);
  }

  @Override
  public String toString() {
    return "Acceleration [xAcceleration=" + xAcceleration + ", yAcceleration=" + yAcceleration
        + ", zAcceleration=" + zAcceleration + "]";
  }
}
